package fr.labri.macchiato.core.api;

import java.util.List;

import fr.labri.macchiato.core.technical.Identifiable;

/**
 * The purpose of a repository is to persist a set of entities identified by an
 * id in a data structure
 * 
 * @param <T>
 *            The type of the entity to persist in the browser's cache
 * @param <Tid>
 *            The type of the entity's identifier
 * @author Matthieu FOUCAULT
 * 
 */
public interface Repository<T extends Identifiable<Tid>, Tid> {

	/**
	 * Saves an entity in the repository. If an entity with the same id already
	 * exists, it is overwritten
	 * 
	 * @param entity
	 *            The entity to save
	 */
	public void save(T entity);

	/**
	 * Loads the entity with the given id from the repository
	 * 
	 * @param id
	 * @return The entity if it is stored in the repository, null otherwise
	 */
	public T load(Tid id);

	/**
	 * Loads all the entities from the repository
	 * 
	 * @return the entities from the repository, an empty list if the repository
	 *         is empty
	 */
	public List<T> loadAll();

	/**
	 * Removes an entity from the repository
	 * 
	 * @param id
	 *            The id of the entity to remove
	 */
	public void remove(Tid id);

	/**
	 * Cleans the repository, e.g. removes all the entities.
	 */
	public void clean();

	/**
	 * 
	 * @return true if the repository is empty, false otherwise
	 */
	public boolean isEmpty();

}
